package com.ruix.app.model;

import com.ruix.app.RuiApplication;
import com.ruix.app.util.LogUitl;
import com.wang.avi.AVLoadingIndicatorView;

import org.json.JSONObject;

/**
 * Created by hadexs on 2017/5/20.
 */

public class AppUpgradeConfig {

    private String review; //最后版本号
    private String latestVersion; //最新版本号
    private String latestVersionUrl; //最新版本下载地址
    private String latestVersionNote; //更新日志
    private boolean latestForce;//是否强制更新 0为不强制 1为强制
    private String commentUrl;//


    public AppUpgradeConfig parse(JSONObject object){
        if (object != null){
            setReview(object.optString("review",""));
            setLatestVersion(object.optString("latest_version",""));
            setLatestVersionUrl(object.optString("latest_version_url",""));
            setLatestVersionNote(object.optString("latest_version_note",""));
            setLatestForce(object.optInt("latest_force",0) == 1);
            setCommentUrl(object.optString("comment_url",""));
        }
        return this;
    }

    public boolean isNeedUpgrade(String currentVersion){
        if (latestVersion != null
                && currentVersion != null){
//            return  latestVersion.compareTo(currentVersion) > 0;
            try {
                return Long.parseLong(latestVersion) > Long.parseLong(currentVersion);
            }catch (Exception e){

            }
        }
        return false;
    }


    public String getReview() {
        return review;
    }

    public void setReview(String review) {
        this.review = review;
    }

    public String getLatestVersion() {
        return latestVersion;
    }

    public void setLatestVersion(String latestVersion) {
        this.latestVersion = latestVersion;
    }

    public String getLatestVersionUrl() {
        return latestVersionUrl;
    }

    public void setLatestVersionUrl(String latestVersionUrl) {
        this.latestVersionUrl = latestVersionUrl;
    }

    public String getLatestVersionNote() {
        return latestVersionNote;
    }

    public void setLatestVersionNote(String latestVersionNote) {
        this.latestVersionNote = latestVersionNote;
    }

    public boolean isLatestForce() {
        return latestForce;
    }

    public void setLatestForce(boolean latestForce) {
        this.latestForce = latestForce;
    }

    public String getCommentUrl() {
        return commentUrl;
    }

    public void setCommentUrl(String commentUrl) {
        this.commentUrl = commentUrl;
    }


    @Override
    public String toString() {
        return "AppUpgradeConfig{" +
                "review='" + review + '\'' +
                ", latestVersion='" + latestVersion + '\'' +
                ", latestVersionUrl='" + latestVersionUrl + '\'' +
                ", latestVersionNote='" + latestVersionNote + '\'' +
                ", latestForce=" + latestForce +
                ", commentUrl='" + commentUrl + '\'' +
                '}';
    }
}
